package com.cskaoyan.order.converter;

import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.dal.entitys.Order;
import com.cskaoyan.order.dal.entitys.OrderItem;
import com.cskaoyan.order.dal.entitys.OrderShipping;
import com.cskaoyan.order.dto.*;
import com.cskaoyan.order.form.OrderDetail;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

@Mapper(componentModel = "spring")
public interface OrderConverter {

    @Mappings({})
    OrderDetailResponse order2res(Order order);

    @Mappings({})
    OrderDetailInfo order2detail(Order order);

    @Mappings({})
    OrderItemDto item2dto(OrderItem item);

    @Mappings({})
    OrderShippingDto shipping2dto(OrderShipping shipping);


    List<OrderItemDto> item2dto(List<OrderItem> items);

    @Mappings({})
    OrderItemResponse item2res(OrderItem orderItem);

    @Mappings({})
    OrderDto order2dto(Order order);

    @Mappings({
            @Mapping(source = "productId", target = "itemId"),
            @Mapping(source = "salePrice", target = "price"),
            @Mapping(source = "productNum", target = "num"),
            @Mapping(source = "productImg", target = "picPath"),
            @Mapping(source = "productName", target = "title")
    })
    OrderItem cartProductDto2OderItem(CartProductDto cartProductDto);

    @Mappings({
            @Mapping(source = "tel", target = "receiverPhone"),
            @Mapping(source = "userName", target = "receiverName"),
            @Mapping(source = "createTime", target = "created"),
            @Mapping(source = "updateTime", target = "updated")
    })
    OrderShipping context2Ordershipping(CreateOrderContext context);

    List<OrderDetailInfo> orderList2ODetailList(List<Order> orderList);

    OrderDetailDto detail2Dto(OrderDetail orderDetail);
}
